var currentPage = 1;
var pageSize = 5;
var totalCount = 0;
var totalPage = 1;

function showInfo() {
    $(".table-page tr td").html("&nbsp;")
    let json = {
        positionid: $("#positionid0").val().trim(),
        name: $("#name0").val().trim(),
        departmentid: $("#departmentid0").val(),
        currentPage: currentPage,
        pageSize: pageSize
    }
    $.ajaxSettings.async = false;
    $.getJSON("/zhiweisel", json, function (dataA) {
        totalCount = dataA.total
        totalPage = dataA.pages
        // < a href=' ' onclick='akbs(" + j.id + ")'><input type='radio' name='xuanze' style='width: 21px;height: 21px' value='"+j.id+"' id='"+j.id+"' /></ a>
        $(dataA.list).each(function (i, v) {
            $(".table-page").find("tr").eq(i + 1).find("td").eq(0).html("<a><input type='radio' name='xuanze' id='xuanze' value='" + v.positionid + "'></a>");
            $(".table-page").find("tr").eq(i + 1).find("td").eq(1).text(v.positionid);
            $(".table-page").find("tr").eq(i + 1).find("td").eq(2).text(v.name);
            $(".table-page").find("tr").eq(i + 1).find("td").eq(3).text(v.sort);
            $(".table-page").find("tr").eq(i + 1).find("td").eq(4).text(v.organization.allName);
        })
    })
    $.ajaxSettings.async = true;
    $("#page").html("&nbsp;" + currentPage + " / " + totalPage + "&nbsp;&nbsp;");
}

//上一页
function prev() {
    currentPage--;
    if (currentPage < 1) {
        currentPage = 1;
        return;
    }
    showInfo();
}

//下一页
function next() {
    currentPage++;
    if (currentPage > totalPage) {
        currentPage = totalPage;
        return;
    }
    showInfo();
}

//首页
function start() {
    currentPage = 1;
    showInfo();
}

//尾页
function end() {
    currentPage = totalPage;
    showInfo();
}
function selPro(){
    currentPage=1;
    totalCount;
    showInfo();

    if(totalCount==0){

        currentPage=1;
        totalPage=1;
        $("#page").text(currentPage+"/"+totalPage);
        return;
    }


}

function xuan() {
    // 方法一
    var item = null;
    var obj = document.getElementsByName("xuanze")
    for (var i = 0; i < obj.length; i++) { //遍历Radio
        if (obj[i].checked) {
            item = obj[i].value;
        }
    }
    let json = {
        positionid: item
    }
    $.ajaxSettings.async = false
    $.getJSON("xuanze", json, function (data) {
        $("#positionName").attr("value", data.name)
        $("#positionId").attr("value", data.positionid)
        $("#sort").attr("value", data.sort)
        layer.close(layer.index)
    })
    $.ajaxSettings.async = true
}

